<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="./localstorage.js"></script>
    <!-- 调用 -->
    <script>
        // set方法
        local.set('user2',{name:'lisi',age:40});
        local.set('user',{name:'lisi',age:40});
        local.set('hid','23344');
        local.set(457,[456,789]);
        local.set([59],{age:123});
  


        // remove方法

        // local.remove('user')
        // localStorage.removeItem('user')           // 可以执行
        
        // local.remove('457')
        // localStorage.removeItem(457)              // 可以执行

        // local.remove([59])
        // localStorage.removeItem([59])             // 可以执行


        // get方法
        console.log(local.get('user2'));   // 纯字符串：{"name":"lisi","age":40}
        console.log(JSON.parse(local.get('user2')));   // 对象：{"name":"lisi","age":40}
        console.log(JSON.parse(local.get(457)));       // 数组：[456, 789]
        console.log(JSON.parse(local.get([59])));      // 对象：{age: 123}

        
        


        // 原有方法测试

        // localStorage.setItem(123,[789,56,'lalal'])            // 如果不转json字符串,存的是'789','56','lalal'
        localStorage.setItem(123,JSON.stringify([789,56,'lalal']))   //   [789,56,lalal] 

        // localStorage.setItem(789,{name:'gagag'})    // 	如果不转json字符串,存的是[object Object]
        localStorage.setItem(789,JSON.stringify({name:'gagag'}))    // 	 {"name":"gagag"}
        // localStorage.removeItem(789)             // 不报错,可以正常移除

        // localStorage.setItem([63],{age:78})        // 如果不转json字符串,存的是[object Object]
        localStorage.setItem([63],JSON.stringify({age:78}))        //  {"age":78};
        // localStorage.removeItem([63])              // 不报错

        // 获取
        console.log(JSON.parse(localStorage.getItem([63])));  // 对象：{age:78}
        console.log(JSON.parse(localStorage.getItem(123)));  // 数组：[789,56,'lalal']



    </script>
</body>
</html>